<?php
/**
* feedback相关逻辑
*
* @author     Robot
* @version    1.0
* @package    Base Framework
* @access     public
* @copyright  商业软件,受著作权保护
* @link       http://***
*/
class postlogModule extends Base
{
	/**
	 * 构造函数
	 *
	 */
	public function __construct(){}

	/**
	 * 记录日志
	 * 
	 */
	public function add($cookie, $args, $result, $sql,$post="",$type=0)
	{
		//log所有提交
		Common::log2file($cookie.' '.var_export($args, true), CACHE_DIR."log/post/postlog_".date("Ymd").".log");

		$oDto = new DTO_User_Postlogs();
		$oDto->cookie = $cookie;
		$oDto->postcontent = Common::encode($args);
		$oDto->nextpost = Common::encode($post);
		$oDto->result = is_array($result) ? join("\n", $result) : $result;
		$oDto->wherecondition = $sql;
		$oDto->type = $type;
		$oDto->createtime = time();
		$oDto->ip = Common::getIpSimple();
		$oDmo = new DMO_User_Postlogs();
		$aKey = array("cookie"=>$cookie);
		$aOrder = array("id"=>"desc");
		$aR = $oDmo->getRow($aKey, $aOrder);
		//和上一次重复
		if(Common::decode($aR['postcontent']) == $args &&Common::decode($aR['nextpost']) == $post)
		{
			return $aR['id'];
		}
		if(!$oDmo->add($oDto))
		{
			throw new MyException("Err001");
		}
		return $oDmo->getInsertId();
	}

	/**
	* 列出日志
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function listlog($aKey, $oPage)
	{
		$aOrder = array("id"=>"desc");

		$oDmo = new DMO_User_Postlogs();
		$aRes = $oDmo->getPage($oPage->getBegin(), $oPage->PerPage, $aKey, $aOrder);
		$oPage->Count = $oDmo->getTotal();
		if($aRes)
		{
			foreach($aRes as $key => $val)
			{
				$aRes[$key]['result'] = explode("\n", $val['result']);
				$aRes[$key]['ipname'] = Common::getIpLocation($val['ip']);
			}
		}

		return $aRes;
	}

	/**
	* 查看日志
	*
	* @access public
	* @param  void
	* @return void
	*/
	public function getLog($id)
	{
		$aKey = array("id"=>$id);
		$oDmo = new DMO_User_Postlogs();
		$aRes = $oDmo->getRow($aKey);
		if($aRes)
		{
			$aRes['postcontent'] = Common::decode($aRes['postcontent']);
			$aRes['nextpost'] = Common::decode($aRes['nextpost']);
			$aRes['result'] = explode("\n", $aRes['result']);
		}

		return $aRes;
	}
}

?>